package com.xayy.mgt.controller;

import cn.kawins.base.result.ResultBody;
import cn.kawins.mybatis.base.BaseController;
import com.github.pagehelper.PageInfo;
import com.xayy.mgt.model.HistoryFault;
import com.xayy.mgt.model.NodeTreeInfo;
import com.xayy.mgt.model.vo.HistoryFaultPageVo;
import com.xayy.mgt.service.HistoryFaultService;
import com.xayy.mgt.service.NodeInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/lsgzyx1")
@Api(tags = "历史故障影响")
public class HistoryFaultController extends BaseController<HistoryFault> {

    @Resource
    private HistoryFaultService historyFaultService;
    @Resource
    private NodeInfoService nodeInfoService;

    @PostMapping("/pageList")
    @ApiOperation(value = "历史故障(分页)", httpMethod = "POST", notes = "历史故障影响-根据parentId分页历史故障")
    public ResultBody pageList(@RequestBody HistoryFaultPageVo nodeInfoDto) {
        PageInfo<HistoryFault> page = historyFaultService.pageList(nodeInfoDto);
        return ResultBody.success(page);
    }


    @PostMapping("/saveHistoryFault")
    @ApiOperation(value = "新增历史故障", httpMethod = "POST", notes = "故障影响-新增历史故障")
    public ResultBody saveHistoryFault(@RequestBody HistoryFault historyFault) {
        NodeTreeInfo nodeTreeInfo = nodeInfoService.selectOne(NodeTreeInfo.builder().id(historyFault.getNodeId()).build());
        historyFault.setComponents(nodeTreeInfo.getNodeName());
        return historyFaultService.saveHistoryFault(historyFault).body();
    }

    @GetMapping("/selectOneHistoryFaultDetail/{id}")
    @ApiOperation(value = "查询历史故障(单个详情)", httpMethod = "GET", notes = "故障影响-查询历史故障(单个详情)")
    public ResultBody selectOneHistoryFaultDetail(@PathVariable Long id) {
        return historyFaultService.selectOneHistoryFaultDetail(id).body();
    }


    @PostMapping("/editHistoryFault")
    @ApiOperation(value = "编辑历史故障", httpMethod = "POST", notes = "故障影响-编辑历史故障")
    public ResultBody editHistoryFault(@RequestBody HistoryFault historyFault) {
        return historyFaultService.editHistoryFault(historyFault).body();
    }


    @DeleteMapping("/deleteHistoryFault/{id}")
    @ApiOperation(value = "删除历史故障", httpMethod = "DELETE", notes = "故障影响-删除历史故障")
    public ResultBody deleteHistoryFault(@PathVariable Long id) {
        return historyFaultService.deleteHistoryFault(id).body();
    }

    @GetMapping("/dataSynchronous")
    @ApiOperation(value = "同步第三方数据", httpMethod = "GET", notes = "历史故障-同步第三方数据")
    public ResultBody dataSynchronous(@RequestParam("nodeId") Long nodeId) {
        return historyFaultService.dataSynchronous(nodeId).body();
    }


}
